using System;
using System.BusinessObjects.Transactions;
using Blazing.BusinessObjects.Tagging;
using NHibernate;
using NHibernate.Criterion;

namespace Blazing.BusinessObjects.Queries
{
    public class QrySearchTags
    {
        public static ICriteria Query()
        {
            ICriteria qry = UnitOfWork.CurrentSession.CreateCriteria(typeof(Tag));
            qry.AddOrder(Order.Asc("Names"));

            qry.SetCacheable(true);
            return qry;
        }

        public static ICriteria Query(string name)
        {
            ICriteria qry = UnitOfWork.CurrentSession.CreateCriteria(typeof(Tag));
            qry.Add(Expression.Eq("Name", name));
            qry.AddOrder(Order.Asc("Name"));

            qry.SetCacheable(true);
            return qry;
        }

        public static ICriteria QueryLike(string name)
        {
            ICriteria qry = UnitOfWork.CurrentSession.CreateCriteria(typeof(Tag));
            qry.Add(Expression.Like("Name", "%"+name+"%"));
            qry.AddOrder(Order.Asc("Name"));

            qry.SetCacheable(true);
            return qry;
        }
    }
}
